﻿


@model Webcar.Entitys.bs_files
@{
    SelectList selectlist = null;
    if (Model.file_type == "LAW")
    {
        selectlist = new SelectList(WebcarDataHelper.LawKind, "Item1", "Item2");
    }
    else
    {
        selectlist = new SelectList(WebcarDataHelper.FileKind, "Item1", "Item2");
    }
    
}
<div style="margin:5px 5px 5px 5px">
@using (Html.BeginForm("New", "File", Html.ViewContext.RouteData.Values, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(a=>a.file_type)
    <div id="edit-car"  style="width:700px;">
    

        <table class="edit-table">
            <tr>
                <td style="text-align: right">上传人：</td>
                <td >@CurrentUser.GetLoginUserName()</td>
            </tr>
            <tr>
                <td style="width: 80px; text-align: right;">上传时间：</td>
                <td>@DateTime.Now.ToDefaultDateTimeString()</td>
            </tr>

            <tr>
                <td style="text-align: right">文件分类：</td>
                <td >@Html.DropDownListFor(a => a.Kind, selectlist)</td>
            </tr>

            <tr>
                <td style="text-align: right">*文件描述：</td>
                <td colspan="3">@Html.TextAreaFor(a=>a.Description,5,30,new{style="width:100%"})</td>
            </tr>
            <tr>
                <td style="text-align: right">附件：</td>
                <td colspan="3">支持格式:rar|zip|doc|xls|ppt|docx，最大4MB </td>
            </tr>
            <tr>
                <td style="text-align: right">文件名：</td>
                <td >@Html.TextBoxFor(a=>a.FileName2)</td>
            </tr>
            <tr>
                <td style="text-align: right">选择附件：</td>
                <td colspan="3"><input type="file" id="fileImage" name="fileImage" /> </td>
            </tr>
        </table>
    </div>
    
    
    <div class="validation-errors">@ViewBag.ErrorMessage</div>
        
    
    
    <table style="width:700px">
        <tr>
            <td style="width:650px;"></td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.Name = "Button1";
                    settings.Text = "保存";
                    settings.UseSubmitBehavior = false;
                    settings.Width = 70;
                    settings.ControlStyle.CssClass = "button1";
                    settings.ClientSideEvents.Click = "function(s, e){ commit_data();}";
                    settings.Enabled = CurrentUser.CheckPermission(PermissionManager.上传文件);
                }).GetHtml()
                

            </td>
            <td>
                @Html.DevExpress().Button(settings =>
                {
                    settings.ControlStyle.CssClass = "button2";
                    settings.Name = "Button2";
                    settings.Text = "取消";
                    settings.Width = 70;
                    settings.ClientSideEvents.Click = "function(s, e){ location.href='" + @Url.Action("List", "File") + "' }";
                }).GetHtml()
            </td>
        </tr>

    </table>
 
    
    <script type="text/javascript">
        $("#fileImage").change(function () {
            var filepath = $("#fileImage").val();
            var filename = filepath.substring(filepath.lastIndexOf("\\") + 1);
            $("#FileName2").val(filename);
        });

        function commit_data() {
            if ($("#FileName2").val() == null || $("#FileName2").val() == "") {
                alert("请输入文件名。");
                return;
            }
            var file = $("#fileImage").val();
            if (file == null || file == "") {
                alert("请选择要上传的文件。");
                return;
            }
            
            var allow_ext = "rar|zip|doc|xls|ppt|docx|";

            if (!check_file("fileImage", allow_ext, 4096)) return;
            document.forms[0].submit();
        };
    </script>
}     
    </div>

